/**
 * Title:		Tester.java
 * Description: This class is the main class from where the Semantic Testing 
 * 				Analysis begins. It is responsible for browsing through the 
 * 				file structure and to populate a Vector with the names of the
 * 				Gold and Debug files and initiate the comparison of the 'gold
 * 				standard test file' with the actual 'debug messages' given out
 * 				by the Interpreter. 
 * 
 * @version		1.0 April 2009
 * @author		Gaurav Pandey
 */

import java.io.*;
import java.util.*;

public class Tester {
	private static Vector<String> vecGoldFiles = new Vector<String>();
	private static Vector<String> vecDebugFiles = new Vector<String>();
	
	public Tester()
	{}
	
	/**
	 * The main function is involved with the tasks concerning browsing the 
	 * files in the test-standard and test-ouput folder and populating them in 
	 * appropriate data structure. Then, we go on calling a filename.debug
	 * from the debug data structure and corresponding filename.gold from the
	 * gold data structure and pass them for Semantic Testing purpose one by
	 * one.
	 * */
	public static void main(String []args) {
		checker();
		int j = 0;
		StringTokenizer goldStr;
		String goldFileName = "";		
		String debugFileName = "";
		String goldString = "";
		Expander ex;
		int goldLength = vecGoldFiles.size();
		int debugLength = vecDebugFiles.size();
		for(int i=0;i<goldLength;i++) {
			GoldTester cc = new GoldTester();
			goldString = vecGoldFiles.get(i);
			goldStr = new StringTokenizer(goldString,".");
			goldFileName = goldStr.nextToken();
			for(j=0;j<debugLength;j++) {
				if(vecDebugFiles.get(j).contains(goldFileName)) {
					debugFileName = vecDebugFiles.get(j);
					ex = new Expander();
					ex.fileReading("validation/semantics/test-standard/"
							+goldString);
					cc.debug(debugFileName);
					cc.gold("validation/semantics/test-standard/test.txt");
					cc.display();
					System.out.println("Gold File: "+goldString+" " +
							"& Debug File: "+debugFileName+" >> Result: " +
									""+(cc.comparer()));
					break;
				}
			}
		}
	}
	
	/**
	 * checker() is called by the Main function and it is chiefly responsible
	 * for populating the Vector Data Structure to insert the names of the 
	 * .gold and .debug files.
	 * */
	public static void checker() {
	
		/**Gold*/
		File directory = new File("validation/semantics/test-standard");
		if(directory.isDirectory()){
			String[] files = directory.list();
			int len = files.length;
			if(len>0){
				for(int i=0;i<len;i++)
					if(files[i].contains(".gold")) {
						vecGoldFiles.add(files[i]);
					}
			}
			else{
				System.out.println("No files exist in the 'Gold' folder");
			}
		}
		else{
			System.out.println("No such Directory 'Gold' exists");
		}
	
		/**Debug*/
		directory = new File("validation/semantics/test-output");
		if(directory.isDirectory()){
			String[] files = directory.list();
			int len = files.length;
			if(len>0){
				for(int i=0;i<len;i++)
					if(files[i].contains(".debug")) {
						vecDebugFiles.add(files[i]);
					}
			}
			else {
				System.out.println("No files exist in the 'Debug' folder");
			}
		}
		else {
			System.out.println("No Directory 'Debug' exists");
		}
	}
}